
const fs = require('fs')
// 导入路径模块
const path = require('path')

// const pathStr = path.join('/a', '/b/c', '../', './d', 'e')

// console.log(pathStr);  // \a\b\d\e

// path.join()拼接路径
fs.writeFile(path.join(__dirname,'/files/3.txt') ,'abcd','utf8',function (err) {
  if (err) {
    console.log('文件写入失败',err.message);  
  }
  console.log('文件写入成功');  

})

// path.nasename()获取文件名
const pathStr = '/a/b/c/index.html'

const fileName = path.basename(pathStr)
// path.extname获取文件扩展名
const extName = path.extname(pathStr)
console.log('扩展名',extName);
const fileNameWithoutExt = path.basename(pathStr,extName)

console.log('文件名',fileName);
console.log('除去扩展名的文件名',fileNameWithoutExt);